//
//  AlertTool.swift
//  visionos_test_demo
//
//  Created by 3tee on 2024/7/29.
//

import UIKit

class AlertTool: NSObject {
    
    func show(_ msg: String,in view: UIView) {
        print("alert show")
        let lab = UILabel()
        lab.text = msg
        lab.font = UIFont.systemFont(ofSize: 25)
        lab.numberOfLines = 0
        lab.sizeToFit()
        lab.frame = CGRect(x: (CGRectGetWidth(view.frame) - lab.frame.width)/2, y: CGRectGetHeight(view.frame) - 44, width: lab.frame.width, height: lab.frame.height)
        view.addSubview(lab)
       DispatchQueue.main.asyncAfter(deadline: .now()+1, execute: DispatchWorkItem(block: {
           lab.removeFromSuperview()
       }))
    }
  
    static func alertShow(_ msg: String,alertVC: UIViewController){
       let vc = UIAlertController(title: nil, message: msg, preferredStyle: .alert)
        alertVC.present(vc, animated: true)
        DispatchQueue.main.asyncAfter(deadline: .now()+1.5, execute: DispatchWorkItem(block: {
            vc.dismiss(animated: true)
        }))
    }
    
}
